import Vue from 'vue'
import VueClipboard from 'vue-clipboard2'

const global = {
  self: this,
  install(Vue) {
    Vue.prototype.global = {
      toPage: (path) => {
        self.$nuxt.$router.push({
          path: path
        })
      },
      openUrl: (path,query) => {
        window.open(path);
      },
      copy: (data, tips='复制成功') => {
        self.$nuxt.$copyText(data).then(res=>{
          self.$nuxt.$message.success(tips);
        })
      },
      parseTimestamp: (val) => {
        let date = new Date(val)
        return `${date.getFullYear()}年${date.getMonth()+1}月${date.getDate()}日`
      },
    }
  }
}

// 使用全局函数
Vue.use(global)
Vue.use(VueClipboard)
